package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.CaractPM;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage CaractPM entities.
 * 
 */
@Repository("CaractPMDAO")
@Transactional
public class CaractPMDAOImpl extends AbstractJpaDao<CaractPM> implements
		CaractPMDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { CaractPM.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new CaractPMDAOImpl
	 *
	 */
	public CaractPMDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findCaractPMByCpmCodeNafContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmCodeNafContaining(String cpmCodeNaf) throws DataAccessException {

		return findCaractPMByCpmCodeNafContaining(cpmCodeNaf, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmCodeNafContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmCodeNafContaining(String cpmCodeNaf, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmCodeNafContaining", startResult, maxRows, cpmCodeNaf);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmQualiteSocieteContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmQualiteSocieteContaining(String cpmQualiteSociete) throws DataAccessException {

		return findCaractPMByCpmQualiteSocieteContaining(cpmQualiteSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmQualiteSocieteContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmQualiteSocieteContaining(String cpmQualiteSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmQualiteSocieteContaining", startResult, maxRows, cpmQualiteSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmTiersContact
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmTiersContact(Integer cpmTiersContact) throws DataAccessException {

		return findCaractPMByCpmTiersContact(cpmTiersContact, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmTiersContact
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmTiersContact(Integer cpmTiersContact, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmTiersContact", startResult, maxRows, cpmTiersContact);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmNomSociete
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNomSociete(String cpmNomSociete) throws DataAccessException {

		return findCaractPMByCpmNomSociete(cpmNomSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmNomSociete
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNomSociete(String cpmNomSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmNomSociete", startResult, maxRows, cpmNomSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByPrimaryKey
	 *
	 */
	@Transactional
	public CaractPM findCaractPMByPrimaryKey(Integer cpmTiers) throws DataAccessException {

		return findCaractPMByPrimaryKey(cpmTiers, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByPrimaryKey
	 *
	 */

	@Transactional
	public CaractPM findCaractPMByPrimaryKey(Integer cpmTiers, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findCaractPMByPrimaryKey", cpmTiers);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiren
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiren(String cpmSiren) throws DataAccessException {

		return findCaractPMByCpmSiren(cpmSiren, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiren
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiren(String cpmSiren, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmSiren", startResult, maxRows, cpmSiren);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiretContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiretContaining(String cpmSiret) throws DataAccessException {

		return findCaractPMByCpmSiretContaining(cpmSiret, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiretContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiretContaining(String cpmSiret, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmSiretContaining", startResult, maxRows, cpmSiret);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmQualiteSociete
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmQualiteSociete(String cpmQualiteSociete) throws DataAccessException {

		return findCaractPMByCpmQualiteSociete(cpmQualiteSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmQualiteSociete
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmQualiteSociete(String cpmQualiteSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmQualiteSociete", startResult, maxRows, cpmQualiteSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmEtatSocieteContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmEtatSocieteContaining(String cpmEtatSociete) throws DataAccessException {

		return findCaractPMByCpmEtatSocieteContaining(cpmEtatSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmEtatSocieteContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmEtatSocieteContaining(String cpmEtatSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmEtatSocieteContaining", startResult, maxRows, cpmEtatSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmChiffreAffaire
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmChiffreAffaire(java.math.BigDecimal cpmChiffreAffaire) throws DataAccessException {

		return findCaractPMByCpmChiffreAffaire(cpmChiffreAffaire, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmChiffreAffaire
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmChiffreAffaire(java.math.BigDecimal cpmChiffreAffaire, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmChiffreAffaire", startResult, maxRows, cpmChiffreAffaire);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmTiers
	 *
	 */
	@Transactional
	public CaractPM findCaractPMByCpmTiers(Integer cpmTiers) throws DataAccessException {

		return findCaractPMByCpmTiers(cpmTiers, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmTiers
	 *
	 */

	@Transactional
	public CaractPM findCaractPMByCpmTiers(Integer cpmTiers, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findCaractPMByCpmTiers", cpmTiers);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findCaractPMByCpmFormeJuridiqueContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmFormeJuridiqueContaining(String cpmFormeJuridique) throws DataAccessException {

		return findCaractPMByCpmFormeJuridiqueContaining(cpmFormeJuridique, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmFormeJuridiqueContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmFormeJuridiqueContaining(String cpmFormeJuridique, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmFormeJuridiqueContaining", startResult, maxRows, cpmFormeJuridique);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmSirenContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSirenContaining(String cpmSiren) throws DataAccessException {

		return findCaractPMByCpmSirenContaining(cpmSiren, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmSirenContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSirenContaining(String cpmSiren, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmSirenContaining", startResult, maxRows, cpmSiren);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiret
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiret(String cpmSiret) throws DataAccessException {

		return findCaractPMByCpmSiret(cpmSiret, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmSiret
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmSiret(String cpmSiret, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmSiret", startResult, maxRows, cpmSiret);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmNbrSalarier
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNbrSalarier(Integer cpmNbrSalarier) throws DataAccessException {

		return findCaractPMByCpmNbrSalarier(cpmNbrSalarier, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmNbrSalarier
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNbrSalarier(Integer cpmNbrSalarier, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmNbrSalarier", startResult, maxRows, cpmNbrSalarier);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmCodeNaf
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmCodeNaf(String cpmCodeNaf) throws DataAccessException {

		return findCaractPMByCpmCodeNaf(cpmCodeNaf, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmCodeNaf
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmCodeNaf(String cpmCodeNaf, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmCodeNaf", startResult, maxRows, cpmCodeNaf);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllCaractPMs
	 *
	 */
	@Transactional
	public Set<CaractPM> findAllCaractPMs() throws DataAccessException {

		return findAllCaractPMs(-1, -1);
	}

	/**
	 * JPQL Query - findAllCaractPMs
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findAllCaractPMs(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllCaractPMs", startResult, maxRows);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmEtatSociete
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmEtatSociete(String cpmEtatSociete) throws DataAccessException {

		return findCaractPMByCpmEtatSociete(cpmEtatSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmEtatSociete
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmEtatSociete(String cpmEtatSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmEtatSociete", startResult, maxRows, cpmEtatSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmNomSocieteContaining
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNomSocieteContaining(String cpmNomSociete) throws DataAccessException {

		return findCaractPMByCpmNomSocieteContaining(cpmNomSociete, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmNomSocieteContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmNomSocieteContaining(String cpmNomSociete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmNomSocieteContaining", startResult, maxRows, cpmNomSociete);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * JPQL Query - findCaractPMByCpmFormeJuridique
	 *
	 */
	@Transactional
	public Set<CaractPM> findCaractPMByCpmFormeJuridique(String cpmFormeJuridique) throws DataAccessException {

		return findCaractPMByCpmFormeJuridique(cpmFormeJuridique, -1, -1);
	}

	/**
	 * JPQL Query - findCaractPMByCpmFormeJuridique
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<CaractPM> findCaractPMByCpmFormeJuridique(String cpmFormeJuridique, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findCaractPMByCpmFormeJuridique", startResult, maxRows, cpmFormeJuridique);
		return new LinkedHashSet<CaractPM>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(CaractPM entity) {
		return true;
	}
}
